<?php
// 学生信息：[您的全名] [学生证号]
// 功能：从JSON加载产品并按WordPress主题风格展示
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Our Coffee - Products</title>
    <!-- 引入WordPress主题一致的样式 -->
    <style>
        /* 基础样式复用WordPress主题风格 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: Arial, sans-serif;
        }
        body {
            background-color: #fff;
            color: #333;
        }
        /* 页眉样式 - 与WordPress一致 */
        .header {
            background: url('head.jpg') center/cover no-repeat;
            padding: 20px 0;
            position: relative;
        }
        .header-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .logo {
            height: 60px; /* 根据实际logo尺寸调整 */
        }
        .nav {
            display: flex;
            gap: 20px;
        }
        .nav a {
            color: #fff;
            text-decoration: none;
            font-weight: bold;
            text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
        }
        /* 页面标题 */
        .page-title {
            text-align: center;
            padding: 40px 0;
            font-size: 2.5rem;
            color: #333;
        }
        /* 产品分类区域 */
        .category-section {
            margin: 40px 0;
        }
        .category-title {
            max-width: 1200px;
            margin: 0 auto 20px;
            padding: 0 20px;
            font-size: 1.8rem;
            color: #333;
            border-bottom: 2px solid #6b4226; /* 咖啡主题棕色 */
            padding-bottom: 10px;
        }
        /* 产品网格 - 响应式布局 */
        .products-grid {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 30px;
        }
        /* 产品卡片样式 */
        .product-card {
            background: #fff;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            transition: transform 0.3s ease;
        }
        .product-card:hover {
            transform: translateY(-5px);
        }
        .product-img {
            width: 100%;
            height: 200px;
            object-fit: cover;
            background: #f5f5f5;
        }
        .product-info {
            padding: 15px;
        }
        .product-name {
            font-size: 1.2rem;
            margin-bottom: 8px;
            color: #333;
        }
        .product-price {
            font-weight: bold;
            color: #6b4226;
            margin-bottom: 5px;
        }
        .product-discount {
            color: #e63946;
            font-size: 0.9rem;
            margin-bottom: 10px;
        }
        .product-desc {
            font-size: 0.9rem;
            color: #666;
            margin-bottom: 10px;
        }
        .product-meta {
            font-size: 0.8rem;
            color: #888;
            margin-top: 10px;
        }
        /* 页脚样式 - 与WordPress一致 */
        .footer {
            background-color: #333;
            color: #fff;
            padding: 40px 0;
            margin-top: 60px;
        }
        .footer-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
            text-align: center;
        }
        .footer-logo {
            height: 40px;
            margin-bottom: 20px;
        }
        .social-links {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-top: 20px;
        }
        .social-links img {
            height: 24px;
            width: 24px;
        }
        /* 响应式调整 */
        @media (max-width: 768px) {
            .products-grid {
                grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            }
            .page-title {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
    <!-- 页眉 - 与WordPress主题一致 -->
    <header class="header">
        <div class="header-content">
            <img src="logo.jpg" alt="Fezco Logo" class="logo">
            <nav class="nav">
               
               
                <a href="products.php">Shop</a>
                
                <a href="../admin/Management.php">Product Management</a>
                <a href="admin/login.php">Admin</a> <!-- 管理入口 -->
            </nav>
        </div>
    </header>

    <!-- 页面标题 -->
    <h1 class="page-title">Our Coffee Products</h1>

    <?php
    // 从JSON文件加载产品数据
    $jsonFile = 'data/products.json';
    $products = [];
    if (file_exists($jsonFile)) {
        $jsonData = file_get_contents($jsonFile);
        $products = json_decode($jsonData, true);
    }

    // 按类别分组产品（假设类别为"Single Origin"和"Blend"）
    $categories = [];
    foreach ($products as $product) {
        $category = $product['category'];
        if (!isset($categories[$category])) {
            $categories[$category] = [];
        }
        $categories[$category][] = $product;
    }

    // 循环展示每个类别下的产品
    foreach ($categories as $categoryName => $categoryProducts) {
    ?>
        <section class="category-section">
            <h2 class="category-title"><?php echo ucfirst($categoryName); ?></h2>
            <div class="products-grid">
                <?php foreach ($categoryProducts as $product) { ?>
                    <div class="product-card">
                        <img src="3.jpg" alt="<?php echo $product['name']; ?>" class="product-img">
                        <div class="product-info">
                            <h3 class="product-name"><?php echo $product['name']; ?></h3>
                            <p class="product-price">
                                <?php if ($product['discount'] > 0) { ?>
                                    <span style="text-decoration: line-through; color: #888;">$<?php echo $product['original_price']; ?></span>
                                    $<?php echo $product['price']; ?>
                                <?php } else { ?>
                                    $<?php echo $product['price']; ?>
                                <?php } ?>
                            </p>
                            <?php if ($product['discount'] > 0) { ?>
                                <p class="product-discount"><?php echo $product['discount']; ?>% Off</p>
                            <?php } ?>
                            <p class="product-desc"><?php echo $product['description']; ?></p>
                            <p class="product-meta">
                                Supplier: <?php echo $product['supplier']; ?><br>
                                Origin: <?php echo $product['origin_country']; ?><br>
                                Roast: <?php echo $product['roast_level']; ?>
                            </p>
                        </div>
                    </div>
                <?php } ?>
            </div>
        </section>
    <?php } ?>

    <!-- 页脚 - 与WordPress主题一致 -->
    <footer class="footer">
        <div class="footer-content">
            <img src="logo.jpg" alt="Fezco Logo" class="footer-logo">
            <p>Proudly powered by WordPress</p>
        </div>
    </footer>
</body>
</html>